package com.twang.stock.controller.old;

import com.google.common.collect.Lists;
import com.twang.stock.Entity.ResponseEntity;
import com.twang.stock.controller.common.BaseControoler;
import com.twang.stock.service.ZhangTingBanTaskService;
import com.twang.stock.email.SendmailService;
import com.twang.stock.task.LongHUDataTask;
import com.twang.stock.task.old.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * Task
 *  1、更新今日数据：以及 May5、May10         http://localhost:8088/stock/updateToDayDataTask
 *  2、查询主力资金历史记录                   http://localhost:8088/stock/moneyInHistory
 *  3、计算板块                             http://127.0.0.1:8080/stock/gaiNianZiJingPaiHangTask
 *  4、分析个股趋势 每日16点00分更新           http://localhost:8088/stock/analyseStockTendTask
 *  5、分析买点 计算强度：每日14点56分更新      http://localhost:8088/stock/strongRize
 */
@Controller
@RequestMapping(value = "/task")
@Slf4j
public class TaskController extends BaseControoler {

    @Autowired
    private AnalyseStockTendTask analyseStockTendTask;

    @Autowired
    private UpdateMay5AndMay10 updateMay5AndMay10;

    @Resource
    private StockMoneyInTask stockMoneyInTask;


    @Autowired
    private AnalyseBuyAndsellTask analyseBuyAndsellTask;

    @Autowired
    private LongHUDataTask longHUDataTask;

    @Autowired
    private UpdateToDayVol updateToDayVol;

    @Autowired
    private QinXuGaoDuTask qinXuGaoDuTask;

    @Autowired
    private SendmailService sendmailService;

    @Autowired
    private 今日精选Task 今日精选Task;

    @Autowired
    private ZhangTingBanTaskService zhangTingBanTaskService;

    /**
     * 更新今日数据：以及 May5、May10
     *  URL：http://127.0.0.1:8081/task/updateToDayDataTask
     * @return
     */
    @RequestMapping(value = "/index")
    @ResponseBody
    public ModelAndView index() {
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("task");
        return  modelAndView;
    }

    /**
     * 更新今日数据：以及 May5、May10
     *  URL：http://127.0.0.1:8081/task/updateToDayDataTask
     * @return
     */
    @RequestMapping(value = "/updateToDayDataTask")
    @ResponseBody
    public ResponseEntity updateToDayDataTask() {
        List list = Lists.newArrayList();
        try {
            updateMay5AndMay10.updateMay5AndMay10();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return responseSuccess(list);
    }

    /**
     * 查询主力资金历史记录
     * URL：http://localhost:8080/task/moneyInHistory
     * @return
     */
    @RequestMapping(value = "/moneyInHistory")
    @ResponseBody
    public ModelAndView moneyInHistory(String stockCode) {
        try {
            stockMoneyInTask.excute();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return new ModelAndView();
    }

    /**
     * 计算板块
     * @return
     * url：http://127.0.0.1:8080/task/今日精选Task
     */
    @RequestMapping(value = "/今日精选Task")
    @ResponseBody
    public ResponseEntity 今日精选Task() {
        今日精选Task.excute();
        return responseSuccess(null);
    }


    /**
     * 分析个股趋势 每日16点00分更新
     * URL：http://localhost:8080/task/analyseStockTendTask
     * @param startDate
     * @param endDate
     * @param code
     * @return
     */
    @RequestMapping(value = "/analyseStockTendTask")
    @ResponseBody
    public ResponseEntity analyseStockTendTask(String startDate,String endDate,String code) {
        List list = Lists.newArrayList();
        try {
            analyseStockTendTask.execut();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return responseSuccess(list);
    }

    /**
     * 分析买点 计算强度：每日14点56分更新
     * URL：http://localhost:8088/stock/strongRize
     * @return
     * http://127.0.0.1:8080/task/strongRize
     */
    @RequestMapping(value = "/strongRize")
    @ResponseBody
    public ResponseEntity strongRize(String stockCode) {
        List list = Lists.newArrayList();
        try {
            analyseBuyAndsellTask.execute();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return responseSuccess(list);
    }

    /**
     * 分析买点 计算强度：每日14点56分更新
     * @return
     * http://127.0.0.1:8080/task/updateToDayVol
     */
    @RequestMapping(value = "/updateToDayVol")
    @ResponseBody
    public ResponseEntity updateToDayVol(String stockCode) {
        List list = Lists.newArrayList();
        try {
            updateToDayVol.excute();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return responseSuccess(list);
    }


    /**
     * 查询高度
     * @return
     * http://127.0.0.1:8080/task/queryHighWeight
     */
    @RequestMapping(value = "/queryHighWeight")
    @ResponseBody
    public ResponseEntity queryHighWeight(String stockCode) {
        List list = Lists.newArrayList();
        try {
            qinXuGaoDuTask.excute();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return responseSuccess(list);
    }

    /**
     * 查询高度
     * @return
     * http://127.0.0.1:8080/task/sendMail
     */
    @RequestMapping(value = "/sendMail")
    @ResponseBody
    public ResponseEntity sendMail(String stockCode) {
        List list = Lists.newArrayList();
        try {
            sendmailService.sendMail("111","222","333","444");
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return responseSuccess(list);
    }

    /**
     * 查询高度
     * @return
     * http://127.0.0.1:8080/task/getTodayLongHuDataList
     */
    @RequestMapping(value = "/getTodayLongHuDataList")
    @ResponseBody
    public void getTodayLongHuDataList(String stockCode) throws Exception {
            longHUDataTask.getTodayLongHuDataList();
    }

    /**
     * 查询主力资金历史记录
     * URL：http://localhost:8080/task/excutePosition
     * @return
     */
    @RequestMapping(value = "/excutePosition")
    @ResponseBody
    public ModelAndView excutePosition(String stockCode) {
        try {
            stockMoneyInTask.updatePosition(Lists.newArrayList("20210719","20210720","20210721","20210722","20210723"));
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return new ModelAndView();
    }

}
